#ifndef CENTRIESMODEL_H
#define CENTRIESMODEL_H

#include <QAbstractTableModel>
#include <QMimeData>

#include "src/cdatabase.h"
#include "src/centry.h"

class CEntriesModel : public QAbstractTableModel
{
    Q_OBJECT

    CDatabase &m_db;
    QString m_id;
    QList<CEntry*> m_list;

    bool m_showHide;

    void debug(QString msg) const { qDebug() << "[EntriesModel]\t" + msg; }

public:
    CEntriesModel(CDatabase &db, QObject *parent = 0);
    ~CEntriesModel();

    QVariant data(const QModelIndex &index, int role) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                         int role = Qt::DisplayRole) const;

    void setId(QString id);
    void changeShowHide() { m_showHide = !m_showHide; reset(); }

    bool showhide() { return m_showHide; }

    CEntry* getEntry(const QModelIndex &) const;
    CEntry* findEntry(QString);
    int findRowNumber(QString);

    QMimeData* mimeData(const QModelIndexList &indexes) const;

public slots:
    void refill();
};

#endif // CENTRIESMODEL_H
